﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using lumo.display.object2D;
using lumo;
using Microsoft.Xna.Framework.Graphics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using FarseerPhysics.Dynamics.Contacts;

namespace game.character.item
{
    /// <summary>
    /// The Fish.
    /// </summary>
    public class HPBarrel : GameEvent
    {
        protected const string _Texture = "Graphics/Items/HPBarrel";
        protected const float HealAmount = 5000.0f;
        /// <summary>
        /// Constructor for RedEnemy.
        /// </summary>
        public HPBarrel(LumoComponent component, GameMap map, Tiled.Object tiledObject)
            : base(component, map, tiledObject)
        {
            // Save the texture.
            Texture = component.Content.Load<Texture2D>(_Texture);
        }

        /// <summary>
        /// Update the character.
        /// </summary>
        /// <param name="component">Update using lumo</param>
        protected override void CreateBody()
        {
            // Create Submarine Body.
            Body = BodyFactory.CreateRectangle(Global.Map.World, Texture.Width / Global.PhysicsScale, Texture.Height / Global.PhysicsScale, 0.125f);
            Body.BodyType = BodyType.Static;
            Body.IsSensor = true;
            Body.IgnoreGravity = true;
            Body.CollisionCategories = Global.PhysicsCategory.Sensor;
            Body.CollidesWith = Global.PhysicsCategory.Actor;
            Body.LinearDamping = 1.0f;
            Body.AngularDamping = 1.0f;
            Body.Restitution = 0.25f;
            Body.OnCollision += OnCollision;
        }

        /// <summary>
        /// Setup the Parameters
        /// </summary>
        protected override void SetupParameters()
        {
            // Setup The coordinates
            Position = new Vector2(_TiledObject.X, _TiledObject.Y);
            SourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
            ScreenOrigin = new Vector2(Texture.Width / 2, Texture.Height / 2);
        }

        /// <summary>
        /// Setup the Artificial Intelligency.
        /// </summary>
        protected override void SetupAI()
        {
        }

        /// <summary>
        /// Setup the Artificial Intelligency.
        /// </summary>
        protected bool OnCollision(Fixture FixA, Fixture FixB, Contact Contact)
        {
            this.Texture = null;
            if (!Deleted)
                _GameMap.Player.Battler.IncreaseHP(HealAmount);
            this.Deleted = true;
            return false;
        }

    }
}
